import java.util.Iterator;
import java.util.LinkedList;

public class LinkedListTest {
    public static void main(String[] args) {
//        LinkedList linkedList = new LinkedList();
//
//        linkedList.addFirst("abc1");
//        linkedList.addFirst("abc2");
//        linkedList.addFirst("abc3");
//        linkedList.addFirst("abc4");
//
//        System.out.println(linkedList);
//
//        System.out.println("removeFirst:"+linkedList.removeFirst());
//
//        Iterator it = linkedList.iterator();
//        while(it.hasNext()){
//            System.out.println(it.next());
//        }

        //队列
        DuiLie duiLie = new DuiLie();
        duiLie.AddDuiLie("abc1");
        duiLie.AddDuiLie("abc2");
        duiLie.AddDuiLie("abc3");
        duiLie.AddDuiLie("abc4");

        while(!duiLie.isNull()){
            System.out.println(duiLie.GetDuiLie());
        }

        //堆栈
        DuiZhan duiZhan = new DuiZhan();
        duiZhan.AddDuiZhan("abc1");
        duiZhan.AddDuiZhan("abc2");
        duiZhan.AddDuiZhan("abc3");
        duiZhan.AddDuiZhan("abc4");

        while(!duiZhan.isNull()){
            System.out.println(duiZhan.GetDuiZhan());
        }
    }
}

/**
 * 队列：先进先出
 */
class DuiLie{
    private LinkedList link;

    DuiLie(){
        this.link = new LinkedList();
    }

    //添加到末尾
    public void AddDuiLie(Object obj){
        link.addLast(obj);
    }

    //出队
    public Object GetDuiLie(){
        return link.removeFirst();
    }

    //判空
    public boolean isNull(){
        return link.isEmpty();
    }
}

/**
 * 堆栈：先进后出
 */
class DuiZhan{
    private LinkedList link;

    DuiZhan(){
        this.link = new LinkedList();
    }

    //添加到头部
    public void AddDuiZhan(Object obj){
        link.addFirst(obj);
    }

    //出栈
    public Object GetDuiZhan(){
        return link.removeFirst();
    }

    //判空
    public boolean isNull(){
        return link.isEmpty();
    }
}